<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/2/8
 * Time: 13:56
 */

function addExpenses($data)
{
    $explain = array(2=>"平台收款手续费",3=>"车险投保提成金额",4=>"推广员收入提成金额",5=>"合作店办理会员提成金额",9=>"商家办理会员提成提成金额",10=>"合作店升级提成金额",
        11=>"商家会员升级提成金额", 12=>"合作店会员充值提成金额",13=>"商家会员充值提成金额",14=>"推荐合伙人");
    $_array = array("category"=>2,"explain"=>$explain[$data["type_id"]],"type_id"=>$data['type_id'],"price"=>$data["price"],"title"=>$explain[$data["type_id"]],
        "create_time"=>date("Y-m-d H:i:s"),"update_time"=>date("Y-m-d H:i:s"));
    if(!empty($data['username'])){
        $_array['username'] = $data['username'];
    }
    \think\Db::table("expenses")->insert($_array);
    return true;
}

/**
 * @param $data
 * @return bool
 * @content 添加补贴记录
 */
function addSubsidy($data)
{
    $_array=array("subsidy_type"=>$data['subsidy_type'],"subsidy_create"=>date("Y-m-d H:i:s"),
        "subsidy_number"=>$data['subsidy_number'],"member_id"=>$data["member_id"]);
    if(!empty($data["pid"])){
        # 商户订单id  服务工单id  合作店任务id  商户任务id
        $_array["pid"]=$data["pid"];
    }
    if(!empty($data["order_number"])){
        $_array["order_number"] = $data["order_number"];
    }
    if(!empty($data["biz_id"])){
        $_array["biz_id"] = $data["biz_id"];
    }
    if(!empty($data["order_type"])){
        $_array["order_type"] = $data["order_type"];
    }
    if(!empty($data["voucher_id"])){
        $_array["voucher_id"] = $data["voucher_id"];
    }
    \think\Db::table("subsidy")->insert($_array);
    return true;
}

/**
 * @return bool
 * @context 激活卡券在小年到除夕不可使用
 */
function voucherDeadLine()
{
    if (date("Y-m-d H:i") >= '2022-01-21 21:00' and date("Y-m-d H:i") <= '2022-02-06 06:00') {
        return false;
    }
    return true;
}

/**
 * @param $memberId
 * @param $verifyInfo
 * @return array
 * @throws \think\db\exception\DataNotFoundException
 * @throws \think\db\exception\ModelNotFoundException
 * @throws \think\exception\DbException
 * @content 用户支付码解析验证
 */
function payCodeVerify($memberId, $verifyInfo)
{
    # 支付二维码验证
    if (empty($memberId) or empty($verifyInfo)) {
        return array('status' => false, 'msg' => '系统错误,参数不全');
    }
    # 解码
    $payCode = authCode($verifyInfo);
    if (empty($payCode)) {
        return array('status' => false, 'msg' => '支付码信息解析失败');
    }
    # 解析手机号
    $phone = explode('mobile', $payCode)[0];

    # 手机号判断
    $memberInfo = \think\Db::table('member')->field('id,member_phone')->where(array('member_phone'=>$phone,'id'=>$memberId))->select();

    if (empty($memberInfo)) {
        return array('status' => false, 'msg' => '请扫描本人付款码');
    }
    # 解析验证码
    $valiCode = explode('valicode', trim(str_replace($phone . 'mobile', '', $payCode)))[0];
    /*$redis = new Redis();
    $redisCode = $redis->hGet('memberPayCode', $memberId);
    if (empty($redisCode)) {
        return array('status' => false, 'msg' => '付款码已过期,请提示用户刷新');
    }
    if ($redisCode != $valiCode) {
        return array('status' => false, 'msg' => '请扫描本人付款码');
    }*/
    # 解析时间
    $timestamp = explode('timestamp', trim(str_replace($phone . 'mobile' . $valiCode . 'valicode', '', $payCode)))[0];
    if ((time() - $timestamp) >= 30) {
        return array('status' => false, 'msg' => '付款码已过期,请提示用户刷新');
    }
    return array('status' => true, 'msg' => '验证通过');
}

/**
 * @param $string
 * @param string $operation
 * @param string $key
 * @param int $expiry
 * @return bool|string
 * @content 生成token(玩家ID  加密/解密)
 */
function authCode($string, $operation = 'DECODE', $key = '', $expiry = 0)
{
    // 动态密匙长度，相同的明文会生成不同密文就是依靠动态密匙
    $ckey_length = 4;
    // 密匙
    $key = md5($key ? $key : '5debd83faf3b1a8b2ea4b00352b7be3c');

    // 密匙a会参与加解密
    $keya = md5(substr($key, 0, 16));
    // 密匙b会用来做数据完整性验证
    $keyb = md5(substr($key, 16, 16));
    // 密匙c用于变化生成的密文
    $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
    // 参与运算的密匙
    $cryptkey = $keya . md5($keya . $keyc);
    $key_length = strlen($cryptkey);
    // 明文，前10位用来保存时间戳，解密时验证数据有效性，10到26位用来保存$keyb(密匙b)，
    //解密时会通过这个密匙验证数据完整性
    // 如果是解码的话，会从第$ckey_length位开始，因为密文前$ckey_length位保存 动态密匙，以保证解密正确
    $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
    $string_length = strlen($string);
    $result = '';
    $box = range(0, 255);
    $rndkey = array();
    // 产生密匙簿
    for ($i = 0; $i <= 255; $i++) {
        $rndkey[$i] = ord($cryptkey[$i % $key_length]);
    }
    // 用固定的算法，打乱密匙簿，增加随机性，好像很复杂，实际上对并不会增加密文的强度
    for ($j = $i = 0; $i < 256; $i++) {
        $j = ($j + $box[$i] + $rndkey[$i]) % 256;
        $tmp = $box[$i];
        $box[$i] = $box[$j];
        $box[$j] = $tmp;
    }
    // 核心加解密部分
    for ($a = $j = $i = 0; $i < $string_length; $i++) {
        $a = ($a + 1) % 256;
        $j = ($j + $box[$a]) % 256;
        $tmp = $box[$a];
        $box[$a] = $box[$j];
        $box[$j] = $tmp;
        // 从密匙簿得出密匙进行异或，再转成字符
        $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
    }
    if ($operation == 'DECODE') {
        // 验证数据有效性，请看未加密明文的格式
        if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
            return substr($result, 26);
        } else {
            return '';
        }
    } else {
        // 把动态密匙保存在密文里，这也是为什么同样的明文，生产不同密文后能解密的原因
        // 因为加密后的密文可能是一些特殊字符，复制过程可能会丢失，所以用base64编码
        return $keyc . str_replace('=', '', base64_encode($result));
    }
}


/**
 * @param int $begin_time 开始时间戳
 * @param int $end_time 结束时间戳
 * @param boolean $mark 时间格式  true=>时间戳  false=>日期格式
 * @return array
 * @content  计算两个时间戳之间相差的日时分秒
 */
function timediff($begin_time, $end_time, $mark = true)
{
    if ($mark == false) {
        # 日期格式,将时间转为时间戳格式
        $begin_time = strtotime($begin_time);
        $end_time = strtotime($end_time);
    }
    # 判断时间大小
    if ($begin_time < $end_time) {
        $starttime = $begin_time;
        $endtime = $end_time;
    } else {
        $starttime = $end_time;
        $endtime = $begin_time;
    }

    //计算天数
    $timediff = $endtime - $starttime;
    $days = intval($timediff / 86400);
    //计算小时数
    $remain = $timediff % 86400;
    $hours = intval($remain / 3600);
    //计算分钟数
    $remain = $remain % 3600;
    $mins = intval($remain / 60);
    //计算秒数
    $secs = $remain % 60;
    $res = array("day" => $days, "hour" => $hours, "min" => $mins, "sec" => $secs);
    return $res;
}

/**
 * @return mixed
 * @content 获取客户端真实ip
 */
function getsIp()
{
    $unknown = 'unknown';
    if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], $unknown)) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], $unknown)) {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    /*
    处理多层代理的情况
    或者使用正则方式：$ip = preg_match("/[\d\.]{7,15}/", $ip, $matches) ? $matches[0] : $unknown;
    */
    if (false !== strpos($ip, ','))
        $ip = reset(explode(',', $ip));
    return $ip;
}

/**
 * 二维数组根据首字母分组排序
 * @param  array $data 二维数组
 * @param  string $targetKey 首字母的键名
 * @return array             根据首字母关联的二维数组
 */
function groupByInitials(array $data, $targetKey = 'name')
{
    $data = array_map(function ($item) use ($targetKey) {
        return array_merge($item, [
            'initials' => getInitials($item[$targetKey]),
        ]);
    }, $data);
    $data = sortInitials($data);
    return $data;
}

/**
 * 按字母排序
 * @param  array $data
 * @return array
 */
function sortInitials(array $data)
{
    $sortData = [];
    foreach ($data as $key => $value) {
        $sortData[$value['initials']][] = $value;
    }
    ksort($sortData);
    return $sortData;
}

/**
 * 获取首字母
 * @param  string $str 汉字字符串
 * @return string 首字母
 */

function getInitials($str)
{
    if (empty($str)) {
        return '#';
    }
    $fchar = ord($str{0});
    if ($fchar >= ord('A') && $fchar <= ord('z')) {
        return strtoupper($str{0});
    }
    $s1 = iconv('UTF-8', 'GBK', $str);
    $s2 = iconv('GBK', 'UTF-8', $s1);
    $s = $s2 == $str ? $s1 : $str;
    $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
    if ($asc >= -20319 && $asc <= -20284) {
        return 'A';
    }

    if ($asc >= -20283 && $asc <= -19776) {
        return 'B';
    }

    if ($asc >= -19775 && $asc <= -19219) {
        return 'C';
    }

    if ($asc >= -19218 && $asc <= -18711) {
        return 'D';
    }

    if ($asc >= -18710 && $asc <= -18527) {
        return 'E';
    }

    if ($asc >= -18526 && $asc <= -18240) {
        return 'F';
    }

    if ($asc >= -18239 && $asc <= -17923) {
        return 'G';
    }

    if ($asc >= -17922 && $asc <= -17418) {
        return 'H';
    }

    if ($asc >= -17417 && $asc <= -16475) {
        return 'J';
    }

    if ($asc >= -16474 && $asc <= -16213) {
        return 'K';
    }

    if ($asc >= -16212 && $asc <= -15641) {
        return 'L';
    }

    if ($asc >= -15640 && $asc <= -15166) {
        return 'M';
    }

    if ($asc >= -15165 && $asc <= -14923) {
        return 'N';
    }

    if ($asc >= -14922 && $asc <= -14915) {
        return 'O';
    }

    if ($asc >= -14914 && $asc <= -14631) {
        return 'P';
    }

    if ($asc >= -14630 && $asc <= -14150) {
        return 'Q';
    }

    if ($asc >= -14149 && $asc <= -14091) {
        return 'R';
    }

    if ($asc >= -14090 && $asc <= -13319) {
        return 'S';
    }

    if ($asc >= -13318 && $asc <= -12839) {
        return 'T';
    }

    if ($asc >= -12838 && $asc <= -12557) {
        return 'W';
    }

    if ($asc >= -12556 && $asc <= -11848) {
        return 'X';
    }

    if ($asc >= -11847 && $asc <= -11056) {
        return 'Y';
    }

    if ($asc >= -11055 && $asc <= -10247) {
        return 'Z';
    }

    return null;
}

/**
 * [CheckMobile 手机号码格式校验]
 * @version  0.0.1
 * @datetime 2020年4月23日15:29:53
 * @param    [int] $mobile [手机号码]
 * @return   bool     [正确true，失败false]
 */
function CheckMobile($mobile)
{
    return (preg_match("/^1[23456789]\d{9}$/", $mobile) == 1) ? true : false;
}

/**
 * 本周的开始日期
 * @param bool $His 是否展示时分秒 默认true
 * @return false|string
 */
function beginWeek($His = true)
{
    $timestamp = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y'));
    return $His ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d', $timestamp);
}

/**
 * 本周的结束日期
 * @param bool $His 是否展示时分秒 默认true
 * @return false|string
 */
function endWeek($His = true)
{
    $timestamp = mktime(23, 59, 59, date('m'), date('d') - date('w') + 7, date('Y'));
    return $His ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d', $timestamp);
}

/**
 * @param $imgUrl
 * @param $mark
 * @return string
 * @content 图片路径整理(返回 http/https)
 */
function imgUrl($imgUrl, $mark = false)
{
    if (!empty($imgUrl) and !is_null($imgUrl)) {
        if (preg_match('/(http:\/\/)|(https:\/\/)/i', $imgUrl)) {
            return $imgUrl;
        }
        $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
        if (!$mark) {
            if (file_exists(ROOT_PATH . "upload/" . $imgUrl)) {
                $imgUrl = str_replace('\\', '/', $imgUrl);
                return $http_type . $_SERVER['HTTP_HOST'] . "/upload/" . $imgUrl;
            } else {
                return "";
            }
        } else {
            if (file_exists(ROOT_PATH . $imgUrl)) {
                $imgUrl = str_replace('\\', '/', $imgUrl);
                return $http_type . $_SERVER['HTTP_HOST'] . '/' . $imgUrl;
            } else {
                return "";
            }
        }
    } else {
        return "";
    }
}

function getMsectimes()
{
    list($msec, $sec) = explode(' ', microtime());
    $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
    return $msectime;
}

/**
 * @param $memberId int 用户id
 * @return mixed
 * @content 查询用户会员等级
 */
function getMemberLevelId($memberId)
{
    $_info = Mysql('mysql')->table('member_mapping')->field('member_level_id')->where(array('member_id' => $memberId))->fetchType(2)->select();
    return $_info[0]['member_level_id'];
}

/**
 * @param $bizId 门店id
 * @return mixed
 * @content 获取门店办理会员的提成
 */
function getBizSettlementRatio($bizId)
{
    $_arr = array(
        'biz1' => 0.05,
        'biz2' => 0.05,
    );
    return $_arr['biz' . $bizId];
}

/**
 * @param string $_url 图片路径
 * @param bool $mark 是否为单张图片标识 , 默认为 true
 * @content 删除图片(删除多张图片时仅支持数组格式)
 */
function delImgInfo($_url, $mark = true)
{
    if ($mark == true) {
        # 删除单张图片
        if (!empty($_url)) {
            $_path = ROOT . 'upload/' . $_url;
            if (file_exists($_path))
                @unlink($_path);
        }
    } else {
        # 多张图片删除 , 仅支持数组
        if (is_array($_url) and !empty($_url)) {
            foreach ($_url as $k => $v) {
                $_path = ROOT . 'upload/' . $v;
                if (file_exists($_path))
                    @unlink($_path);
            }
        }
    }
}

/**
 * @param $str 整个字符串
 * @param $leftStr  左边字符
 * @param $rightStr  右边字符
 * @content 获取某个字符串的中间的内容
 * @return bool|string
 */
function getSubstr($str, $leftStr, $rightStr)
{
    $left = strpos($str, $leftStr);
    //echo '左边:'.$left;
    $right = strpos($str, $rightStr, $left);
    //echo '<br>右边:'.$right;
    if ($left !== false and $right !== false) {
        if ($left < 0 or $right < $left) return '';
        return substr($str, $left + strlen($leftStr), $right - $left - strlen($leftStr));
    } else {
        return '';
    }
}

/**
 * @param $imgUrl 图片地址
 * @return string
 * @content  生活超市地址处理
 */
function getSupermarketImgUrl($imgUrl)
{
    $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
    return $http_type . "www.elianchefu.com:8080/uploads/" . $imgUrl;
}

/**
 * @param $_delivery
 * @return null|string
 * @content 生活超市配送方式
 */
function getSupermarketDelivery($_delivery)
{
    if (!empty($_delivery)) {
        switch ($_delivery) {
            case 1:
            default:
                return '到店自提';
                break;
            case 2:
                return '送货上门';
                break;
            case 3:
                return '包邮';
                break;
        }
    } else {
        return null;
    }
}

/**
 * @access protected
 * @param $arr
 * @context 卡券金额格式转换
 * @return mixed
 */
function cardPriceChange($arr)
{
    if (!empty($arr)) {
        foreach ($arr as $k => $v) {
            $price = explode(".", $v['price']);
            $arr[$k]['price1'] = $price[0];
            $arr[$k]['price2'] = $price[1];
        }
    }
    return $arr;
}

/**
 * @param $_id
 * @return string
 * @content  根据工单id查询服务名称
 */
function getOrderServerTitle($_id)
{
    $_receipt = '';
    if (!empty($_id)) {
        $_res = Mysql('mysql')->query("select if(os.custommark = 1,(select service_title from service s where s.id = os.server_id limit 1),(select custom_server_title from customserver cs where cs.id = os.server_id limit 1)) title from order_server os where id eq " . $_id);
        if (!empty($_res)) {
            $_receipt = $_res[0]['title'];
        }
    }
    return $_receipt;
}

/**
 * @param $type 上传文件的类型
 * @param $size 上传文件的大小
 * @param $name 上传文件的名称
 * @param $path 上传文件的临时路径
 * @content 上传图片至 public/epublic/img
 * @return array
 */
function uploads($type, $size, $name, $path)
{
    //判断上传的文件是否出错,是的话，返回错误
    if ($_FILES["file"]["error"]) {
        return array('return_code' => false, 'return_msg' => $_FILES["file"]["error"]);
    } else {
        //没有出错
        //加限制条件
        //判断上传文件类型为png或jpg且大小不超过1024000B
        if (($type == "image/png" || $type == "image/jpeg") && $size < 1024000) {
            # 文件名
            $filename = __PUBLIC__ . "/epublic/img/" . $name;
            //转码，把utf-8转成gb2312,返回转换后的字符串， 或者在失败时返回 FALSE。
            $filename = iconv("UTF-8", "gb2312", $filename);
            //保存文件,   move_uploaded_file 将上传的文件移动到新位置
            $_receipt = move_uploaded_file($path, $filename);//将临时地址移动到指定地址
            if ($_receipt) {
                return array('return_code' => true);
            } else {
                return array('return_code' => false);
            }
        } else {
            return array('return_code' => false, 'return_msg' => "文件不符合标准");
        }
    }
}

/**
 * @param $biz
 * @return string
 * @content  门店后台添加操作记录的门店文件夹
 */
function getLogsType($biz)
{
    if ($biz == 1) {
        return 'LOG_ECARBIZ';
    }
}

/**
 * @access public
 * @param int $type 卡券类型
 * @content 获取卡券类型
 * @return string 卡券类型名称
 */
function getTypeTitle($type)
{
    if (intval($type)) {
        switch ($type) {
            case 1:
                return '商品通用抵值券';
                break;
            case 2:
                return '服务通用抵值券';
                break;
            case 3:
                return '单独商品抵值券';
                break;
            case 4:
                return '单独服务抵值券';
                break;
            case 5:
                return '商品,服务通用抵值券';
                break;
            case 6:
                return '现金抵值通用券';
                break;
            case 7:
                return "联盟商家";
                break;
            case 8:
                return "本地生活";
                break;
            case 9:
                return "物业消费";
                break;
            case 10:
                return "有派精品购";
                break;
            case 11:
                return "服务通用券";
                break;
            case 12:
                return "商品通用券";
                break;
            case 13:
                return "全部通用券";
                break;
            case 14:
                return "服务分类券";
                break;
            case 15:
                return "商品分类券";
                break;
            case 16:
                return "全部分类券";
                break;
            case 17:
                return '会员办理抵值券';
                break;
        }
    } else {
        return null;
    }
}

/**
 * @param $person
 * @param $person_level
 * @content 查询现金红包开放人群
 * @return null|string
 */
function getRedPacketPersonInfo($person, $person_level)
{
    $_receipt = null;
    if ($person == 4) {
        # 查询会员等级名称'
        $level_title = Mysql('mysql')->table('member_level')->field(array('level_title'))->where(array('id' => $person_level))->select();
        $_receipt = $level_title[0]['level_title'];
    } else {
        switch ($person) {
            case 1:
                $_receipt = '已关注用户';
                break;
            case -1:
                $_receipt = '未关注用户';
                break;
            case 2:
                $_receipt = '注册用户';
                break;
            case -2:
                $_receipt = '非注册用户';
                break;
            case 3:
                $_receipt = '所有会员';
                break;
            case -3:
                $_receipt = '所有非会员';
                break;
            case 0:
                $_receipt = "所有用户";
                break;
        }
    }
    return $_receipt;
}

/**
 * @content 获取活动状态配置文件
 */
function getActiveStatusCfg()
{
    return include("ActiveStatus.cfg.php");
}

/**
 * @content 查询赠送东西的价格
 * @param $type int 类型
 * @param $giving_id int 赠送东西的id
 * @return string
 */
function getGivingPrice($type, $giving_id)
{
    if ($type == 2) {
        # 服务门店最低价格
        $price = Mysql('mysql')->table('service_car_mediscount')->field('discount')->where(array('service_id' => $giving_id, 'service_type' => 2))->order(array('discount' => 'asc'))->limit(1)->select();
        $price = $price[0]['discount'];
    } elseif ($type == 1) {
        $price = Mysql('mysql')->table('biz_pro')->field('biz_pro_price')->where(array('id' => $giving_id))->select();
        $price = $price[0]['biz_pro_price'];
    } elseif ($type == 3) {
        $price = Mysql('mysql')->table('card_voucher')->field('card_price')->where(array('id' => $giving_id))->select();
        $price = $price[0]['card_price'];
    }
    return $price;
}

/**
 * @content 拼接赠送东西的数量(单位)
 * @param $type int 类型
 * @param $giving_number 赠送东西的数量
 * @return string
 */
function getGivingNumber($type, $giving_number)
{
    if ($type == 2) {
        # 服务
        return $giving_number . "次";
    } elseif ($type == 1) {
        # 商品
        return $giving_number . "个";
    } elseif ($type == 3) {
        return $giving_number . "张";
    } else {
        return $giving_number;
    }

}

/**
 * @content 生成流水号
 * @return string
 */
function getSerialNumber()
{
    $_receipt = null;
    # 查询当天的最后一个流水号
    $serial_number = Mysql('mysql')->table('serial_number')->field(array('serial_number'))->where("create_time ge '" . date("Y-m-d 00:00:01") . "' and create_time le '" . date("Y-m-d 23:59:59") . "'")->fetchType(2)->order(array('id' => 'desc'))->limit(1)->select();
    if (!empty($serial_number)) {
        # 流水号加1
        $_receipt = $serial_number[0]['serial_number'] + 1;
    } else {
        # 生成流水号
        $_receipt = date("Ymd") . "30310001";
    }
    # 将流水号写回数据库
    $res = Mysql('mysql')->table('serial_number')->data(array('serial_number' => $_receipt, 'create_time' => date("Y-m-d H:i:s")))->insert();
    if ($res)
        return $_receipt;
    else
        return $_receipt . "X";
}

/**
 * @access public
 * @param $member_id
 * @return mixed
 * @context
 */
function getphoneNumber($member_id)
{
    if (!empty($member_id)) {
        $phone = Mysql('mysql')->table('member')->field('member_phone')->where(array('id' => $member_id))->fetchType(2)->select();
        if (!empty($phone)) {
            return $phone[0]['member_phone'];
        }
    } else {
        return null;
    }
}

/**
 * @access public
 * @param int $_car_level
 * @return string
 * @context 根据车辆等级查询名称
 */
function getCarLevel($_car_level)
{

    $_receipt = null;
    $_receipt = Mysql('mysql')->table('car_level')->field('level_title')->where(array('id' => $_car_level))->fetchType(2)->select();
    if ($_receipt) {
        $_receipt = $_receipt[0]['level_title'];
    }
    return $_receipt;
}

/**
 * @access public
 * @param $id
 * @content 根据车型选择车系
 */
function getCarLogo($id)
{
    $_sort = Mysql('mysql')->table('car_sort')->field(array('id', 'sort_title', 'level'))->where(array('logo_id' => $id))->fetchType(2)->select();
    $_logo = null;
    if ($_sort) {
        foreach ($_sort as $k => $v) {
            $_logo .= '<div class="panel-body" onclick="addcar(' . $v['id'] . ')">
				<span class="panelc"></span>' . $v['sort_title'] . '
			</div>';
        }
    }
    return $_logo;

}

/**
 * @access public
 * @param $name string 微信昵称
 * @content 微信昵称base64格式转化
 */
function getName($name)
{
    return base64_decode(trim($name));
}

/**
 * @content 获取模板消息要用的值
 */
function getTemplate()
{
    return include("Template.cfg.php");
}

/**
 * @param $type 消息类型
 * @content 根据消息类型显示链接地址
 * @return string
 */
function getMessageType($type)
{
    switch ($type) {
        case 1:
            return '<a href="/Epublic/Mine/beltComment.html">去评论</a>';
            break;
        default :
            return null;
            break;
    }
}

/**
 * @param car_id 车辆id
 * @context 根据车辆id 查询车辆的公里数
 * @return mixed
 */
function getCarMileage($car_id)
{
    $_receipt = Mysql('mysql')->table('member_car')->field(array('car_mileage'))->where(array('id' => $car_id))->fetchType(2)->select();
    return $_receipt[0]['car_mileage'];
}

/**
 * @context 公众号判断是否存在session，否则直接跳转之首页
 */
function checkSession()
{
    if (empty(Session('member_id')) and is_null(Session('member_id'))) {
        header("location:/Epublic/index/home.html");
    }
}

/**
 * @param $type 会员等级
 * @return string
 * @context 根据会员等级展示会员卡图片
 */
function getLevelPic($type)
{
# 根据会员等级判断显示会员卡图片
    if (intval($type)) {
        switch ($type) {
            case 1:
                return 'vip1.png';
                break;
            case 2:
                return 'vip2.png';
                break;
            case 3:
                return 'vip3.png';
                break;
            case 4:
                return 'vip4.png';
                break;
            case 5:
                return 'vip5.png';
                break;
            case 6:
                return 'vip6.png';
                break;
            case 7:
                return 'vip7.png';
                break;
            case 8:
                return 'vip8.png';
                break;
        }
    }
}

/**
 * @access function
 * @param string $file 上传文件的字段名
 * @param int $size 上传文件的尺寸
 * @return string
 * @context 文件上传的方法
 */
function upload($file = null, $size = 1024000000)
{
    $upload = new \Origin\Kernel\File\Upload($file);
    $upload->size($size);
    $upload->type(array('jpg', 'png', 'gif', 'jpeg'));
    $upload->save('upload');
    actionLogs('datetime' . time() . microtime());
    $_excels = $upload->update(false);
    if ($upload->getErrorMsg() == "ERROR_0000")
        return $_excels;
    else
        return null;
}

/**
 * @access function
 * @param string $address 地址
 * @param string $city 城市
 * @return array
 * @context 地理编码
 */
function getLonLat($address, $city = null)
{
    $_receipt = null;
    $url = "https://restapi.amap.com/v3/geocode/geo?key=3f5396b83b7b09cfb811027943f8d7c7&address=" . trim($address) . "&city=" . trim($city);
    $_curl = new \Origin\Kernel\Protocol\Curl();
    $_receipt = $_curl->get($url);
    return json_decode($_receipt, true);
}

/**
 * @access public
 * @param int $_sex_number
 * @return  string
 * @context 性别查询展示
 */
function getSex($_sex_number)
{
    switch (intval($_sex_number)) {
        case 2:
            return "未设置";
            break;
        case 1:
            return "男";
            break;
        case 0:
        default:
            return "女";
            break;
    }
}

/**
 * @access public
 * @param int $member_level_id
 * @return string
 * @context 会员等级
 */
function getLevel($member_level_id)
{
    switch (intval($member_level_id)) {
        case 0:
        default:
            return "普通用户";
            break;
        case 1:
            return "初级体验";
            break;
        case 2:
            return "体验Vip";
            break;
        case 3:
            return "银色Vip";
            break;
        case 4:
            return "黄金Vip";
            break;
        case 5:
            return "白金Vip";
            break;
        case 6:
            return "如意Vip";
            break;
        case 7:
            return "贵宾Vip";
            break;
        case 8:
            return "钻石Vip";
            break;
        case 9:
            return "至尊Vip";
            break;
    }
}

/**
 * @access public
 * @param int $member_car_id
 * @return string
 * @context 查询车辆品牌
 */
function getCar($member_car_id)
{
    /*$_receipt = Mysql('mysql')->query("select car_licens,
                                          (select brand_title from brand where brand.id eq 
                                          (select brand_id from brand_type where brand_type.id = member_car.id)) as car_title 
                                          from member_car where id = '" . $member_car_id . "';");*/
    $_receipt = Mysql('mysql')->query("select mc.id,
                    (select level_title from car_level as cle where cle.id = (select level from car_sort as cs where cs.id = mc.car_type_id) ) as level,
                    (select sort_title from car_sort as cs where cs.id = mc.car_type_id ) as sort_title,
                    (select title from car_logo as cl where cl.id = (select logo_id from car_sort as cs where cs.id = mc.car_type_id)) as logo_title
                     from member_car as mc where mc.id = '" . $member_car_id . "';");
    return "
           <td style=\"text-align: center\">" . $_receipt[0]['sort_title'] . "</td>";
}

/**
 * @access public
 * @param int $member_status
 * @return string
 * @context 查询用户状态
 */
function getStatus($member_status)
{
    switch (intval($member_status)) {
        case 0:
            return "<td style=\"text-align: center\"><span class='label'>停用</span></td>";
            break;
        case 1:
        default:
            return "<td style=\"text-align: center\"><span class='label label-success'>普通</span></td>";
            break;
        case 2:
            return "<td style=\"text-align: center\"><span class='label label-info'>已实名制</span></td>";
            break;
    }
}

/**
 * @access public
 * @param int $employee_status
 * @return string
 * @context 查询员工状态
 */
function getEStatus($employee_status)
{
    switch (intval($employee_status)) {
        case 0:
            return "<td style=\"text-align: center\"><span class='label'>离职</span></td>";
            break;
        case 1:
        default:
            return "<td style=\"text-align: center\"><span class='label label-success'>试用期</span></td>";
            break;
        case 2:
            return "<td style=\"text-align: center\"><span class='label label-info'>已转正</span></td>";
            break;
    }
}

/**
 * @access public
 * @return string
 * @context 查询总门店名称,id(用于创建门店时选择门店级别)
 */
function getBizList()
{
    $_receipt = Mysql('mysql')->table('biz')->field(array('id', 'biz_title'))->where(array('biz_mark' => 0))->fetchType(2)->select();
    return $_receipt;
}

/**
 * @access public
 * @param int $mark 分店标识
 * @return string
 * @context 查询总门店名称,id(用于创建门店时选择门店级别)
 */
function getBizMark($mark)
{
    $_return = null;
    if (intval($mark) == 0) {
        $_return = '是';
    } else {
        $biz_title = Mysql('mysql')->table('biz')->field(array('biz_title'))->where(array('id' => intval($mark)))->fetchType(2)->select();
        if (!empty($biz_title)) {
            $_return = $biz_title[0]['biz_title'];
        }
    }
    return $_return;
}

/**
 * @access public
 * @param int $type 门店分类
 * @return string
 * @context 门店分类名称
 */
function getBizType($type)
{
    switch (intval($type)) {
        case 1:
        default:
            return "自营";
            break;
        case 2:
            return "加盟";
            break;
        case 3:
            return "合作";
            break;
    }
}

/**
 * @access public
 * @param int $_status
 * @return string
 * @context 查询门店状态
 */
function getBizStatus($_status)
{
    switch (intval($_status)) {
        case 0:
            return "<td style=\"text-align: center\"><span class='label'>停用</span></td>";
            break;
        case 1:
        default:
            return "<td style=\"text-align: center\"><span class='label label-success'>启用</span></td>";
            break;
        case 2:
            return "<td style=\"text-align: center\"><span class='label label-info'>待审核</span></td>";
            break;
    }
}

/**
 * @access public
 * @param int $_pid
 * @return string
 * @context 查询服务分类名称
 */
function getSerCla($_pid)
{
//    $_return = null;
    $_return = Session('getSerClaInfo' . $_pid);
    if (empty($_return)) {
        if (intval($_pid) == 0) {
            $_return = "最高级";
        } else {
            $_title = Mysql('mysql')->table('service_class')->field(array('service_class_title'))->where(array('id' => $_pid))->fetchType(2)->select();
            if (!empty($_title)) {
                $_return = $_title[0]['service_class_title'];
            }
        }
        Session('getSerClaInfo' . $_pid, $_return);
    }
    return $_return;
}

/**
 * @access public
 * @param int $_num
 * @return string
 * @context 评价星星数量展示
 */
function getStar($_num)
{
    switch (intval($_num)) {
        case 1:
        default:
            return '<i class="icon-star"></i>';
            break;
        case 2:
            return '<i class="icon-star"></i><i class="icon-star"></i>';
            break;
        case 3:
            return '<i class="icon-star"></i><i class="icon-star"></i><i class="icon-star"></i>';
            break;
        case 4:
            return '<i class="icon-star"></i><i class="icon-star"></i><i class="icon-star"></i><i class="icon-star"></i>';
            break;
        case 5:
            return '<i class="icon-star"></i><i class="icon-star"></i><i class="icon-star"></i><i class="icon-star"></i><i class="icon-star"></i>';
            break;

    }
}

/**
 * @access public
 * @param int $_biz_id
 * @return string
 * @context 根据订单id查询门店名称(用于评价表展示)
 */
/*function getBizTitle($_biz_id)
{
    $_receipt = null;
    $title = Mysql('mysql')->table('biz')->field(array('biz_title'))->where(array('id' => $_biz_id))->fetchType(2)->select();
    if (!empty($title)) {
        $_receipt = $title[0]['biz_title'];
    }
    return $_receipt;
}*/

/**
 * @access public
 * @param int $_order_id
 * @return string
 * @context 根据订单id查询订单类型名称(用于评价表展示)
 */
function getOrderType($_order_id)
{
    $order_type = null;
    $type = Mysql('mysql')->table('orders')->field(array('order_type'))->where(array('id' => intval($_order_id)))->fetchType(2)->select();
    if (!empty($type)) {
        switch (intval($type[0]['order_type'])) {
            case 1:
            default:
                return "服务评价";
                break;
            case 2:
                return "商品评价";
                break;
            case 3:
                return "活动评价";
                break;
        }
    }
}

/**
 * @access public
 * @param int $_reception_id
 * @return string
 * @context 根据接待人员id 查询员工姓名(用于评价表展示)
 */
function getRName($_reception_id)
{
    $_receipt = null;
    if (!empty($_reception_id)) {
        $_id = array_filter(explode(',', $_reception_id));
        $_reception_id = implode(',', $_id);
        if (strlen($_reception_id) == 1) {
            # 单个员工
            $name = Mysql('mysql')->table('employee')->field(array('employee_name'))->where(array('id' => intval($_reception_id)))->fetchType(2)->select();
            if (!empty($name)) {
                $_receipt = $name[0]['employee_name'];
            }
        } else {
            # 多个员工
            $name = Mysql('mysql')->table('employee')->field(array('employee_name'))->where("id in (" . $_reception_id . ")")->fetchType(2)->select();
            if (!empty($name)) {
                foreach ($name as $k => $v) {
                    $_receipt .= $v['employee_name'] . "、";
                }
                $_receipt = trim($_receipt, "、");
            }
        }
    }
    return $_receipt;
}

/**
 * @access public
 * @param $id 员工id
 * @return string
 * @content 评论管理中获取岗位名称
 */
function getEvaluationJobsTitle($id)
{
    # 初始化返回值
    $_return = null;
    if (!empty($id)) {
        $_id = array_filter(explode(',', $id));
        $id = implode(',', $_id);
        if (strlen($id) == 1) {
            # 单个员工
            $jobTitle = Mysql('mysql')->query("select jobs_title from jobs left join employee on jobs.id eq employee.jobs_id where employee.id eq " . $id);
            $_return = $jobTitle[0]['jobs_title'];
        } else {
            # 多个员工
            $jobTitle = Mysql('mysql')->query("select jobs_title from jobs left join employee on jobs.id eq employee.jobs_id where employee.id in (" . $id . ")");
            if (!empty($jobTitle)) {
                foreach ($jobTitle as $k => $v) {
                    $_return .= $v['jobs_title'] . "、";
                }
                $_return = trim($_return, "、");
            }
        }
    }
    return $_return;
}

/**
 * @access public
 * @param int $_biz_id
 * @return string
 * @context 根据门店id查询门店名称
 */
/*function getBizName($_biz_id)
{
    $_receipt = null;
    $biz_title = Mysql('mysql')->table('biz')->field(array('biz_title'))->where(array('id' => intval($_biz_id)))->fetchType(2)->select();
    if (!empty($biz_title)) {
        $_receipt = $biz_title[0]['biz_title'];
    }
    return $_receipt;
}*/

/**
 * @access public
 * @param int $_department_id
 * @return string
 * @context 根据部门id查询部门名称
 */
/*function getDepartment($_department_id)
{
    $_receipt = null;
    $department_title = Mysql('mysql')->table('department')->field(array('department_title'))->where(array('id' => intval($_department_id)))->fetchType(2)->select();
    if (!empty($department_title)) {
        $_receipt = $department_title[0]['department_title'];
    }
    return $_receipt;
}*/

/**
 * @access public
 * @param int $_jobs_id
 * @return string
 * @context 根据岗位id查询岗位名称
 */
/*function getJobsName($_jobs_id)
{
    $_receipt = null;
    $jobs_title = Mysql('mysql')->table('jobs')->field(array('jobs_title'))->where(array('id' => intval($_jobs_id)))->fetchType(2)->select();
    if (!empty($jobs_title)) {
        $_receipt = $jobs_title[0]['jobs_title'];
    }
    return $_receipt;
}*/

/**
 * @access public
 * @param int $_team_id
 * @return string
 * @context 根据团队id 查询团队名(工位列表)
 */
function getTTitle($_team_id)
{
    $_receipt = Mysql("mysql")->table("team")->field(array("team_name"))->where(array('id' => $_team_id))->select();
    if (!empty($_receipt)) {
        return $_receipt[0]['team_name'];
    }
    return null;
}

/**
 * @access public
 * @param int $type 消费类型
 * @return string
 * @context 消费类型
 */
function getConsump_type($type)
{
    switch (intval($type)) {
        case 1:
        default:
            return "线上支付";
            break;
        case 2:
            return "门店支付";
            break;
    }
}

/**
 * @access public
 * @param int $type 支付类型
 * @return string
 * @context 支付类型
 */
function getpay_type($type)
{
    switch (intval($type)) {
        case 6:
            return "卡券支付";
            break;
        case 5:
        default:
            return "余额支付";
            break;
        case 1:
            return "微信支付";
            break;
        case 2:
            return "支付宝支付";
            break;
        case 3:
            return "银联支付";
            break;
        case 4:
            return "现金支付";
            break;
    }
}

/**
 * @access public
 * @param int $pid 用户id
 * @return string
 * @context 根据用户id 查找用户姓名(用户详情推荐人展示)
 */
function getMemberName($pid)
{
    $_receipt = null;
    $_receipt = Mysql('mysql')->table('member')->field(array('member_name', 'nickname'))->where(array('id' => intval($pid)))->fetchType(2)->select();
    if (!empty($_receipt)) {
        if (!empty($_receipt[0]['member_name'])) {
            $_res = $_receipt[0]['member_name'];
        } else {
            $_res = base64_decode($_receipt[0]['nickname']);
        }
    } else {
        $_res = '未注册用户';
    }
    return $_res;
}

/**
 * @access public
 * @param int $pid 员工id
 * @param int $type 用于展示的页面
 * @return string
 * @context 查找用户的注册渠道,推荐人(用户详情推荐人,门店展示)
 */
function getChannel($pid, $type = null)
{
    $_receipt = null;
    if (!empty($pid)) {
        $_receipt = Mysql('mysql')->query("select employee.id as eid,employee_name,biz_id,biz_title from employee left join biz on biz.id = biz_id where employee.id eq " . intval($pid));
    }
    if ($_receipt) {
        $_res = "<td style=\"text-align: center\"><a id='biz' href='/ecars/biz/index.html?active=search&search=" . $_receipt[0]['biz_id'] . "'>" . $_receipt[0]['biz_title'] . "</td>
                            <td style=\"text-align: center\">" . $_receipt[0]['employee_name'] . "</td>";
    } else {
        $_res = "<td style=\"text-align: center\">门店注册</td>
                            <td style=\"text-align: center\">无</td>";
    }
    if ($type == 1) {
        return $_receipt[0]['employee_name'];
    } else {
        return $_res;
    }
}

function getChannels($biz_id)
{
    $bizTitle = getBizTitle($biz_id);
    return "<td style=\"text-align: center\"><a id='biz' href='/ecars/biz/index.html?active=search&search=" . $biz_id . "'>" . $bizTitle . "</td>
                            <td style=\"text-align: center\">无</td>";
}

/**
 * @access public
 * @return string
 * @context 查询所有车辆品牌信息
 */
function car_logo()
{
    $_receipt = null;
    $_receipt = Mysql('mysql')->table('car_logo')->field(array('id', 'title'))->fetchType(2)->select();
    if ($_receipt) {
        return $_receipt;
    }
    return $_receipt;
}

/**
 * @access public
 * @param int $_jobs_id 岗位id
 * @return string
 * @context 查找对应门店下每个岗位的人数
 */
function getEcount($_jobs_id)
{
    $_receipt = Mysql('mysql')->query("select count(id) as `count` from employee where jobs_id eq " . $_jobs_id . " and biz_id eq 1");
    return $_receipt[0]['count'];
}

/**
 * @access public
 * @param int $_type
 * @return  string
 * @context 消费类型
 */
function getTrafficType($_type)
{
    switch (intval($_type)) {
        case 1:
        default:
            return "车辆服务";
            break;
        case 2:
            return "积分兑换";
            break;
        case 3:
            return "购买商品";
            break;
        case 4:
            return "办理会员";
            break;
        case 5:
            return "其他";
            break;
    }
}

/**
 * @access public
 * @param int $_member_id
 * @return  string
 * @context 查询用户的一个车牌号(门店管理系统)
 */
function getCarLicens($_member_id)
{
    $car = null;
    $member_car = Mysql('mysql')->table('member_car')->field(array('car_licens'))->where(array('member_id' => $_member_id))->fetchType(2)->limit(1)->select();
    if (!empty($member_car))
        $car = $member_car[0]['car_licens'];
    return $car;
}

/**
 * @access public
 * @param int $_member_id
 * @return  string
 * @context 查询用户的一个车牌号,车系(大后台用户列表)
 */
function getCarInfo($_member_id)
{
    $car = null;
    $sort = null;
    $member_car = Mysql('mysql')->table('member_car')->field(array('car_licens', 'car_type_id'))->where(array('member_id' => $_member_id))->fetchType(2)->limit(1)->select();
    if (!empty($member_car))
        $car = $member_car[0]['car_licens'];
    $sort = Mysql('mysql')->table('car_sort')->field(array('sort_title'))->where(array('id' => $member_car[0]['car_type_id']))->fetchType(2)->select();
    //<td width='10%' height='10px'>" . $sort[0]['sort_title'] . "</td>
    return "<td width='10%' height='10px'>" . $car . "</td>";
}

/**
 * @access public
 * @param int $_service_id
 * @return  string
 * @context 服务列表中会员折扣查询
 */
function getServiceMediscount($_service_id)
{
//    $_return = null;
    $_return = Session('serviceMediscountInfo' . $_service_id);
    if (empty($_return)) {
        if ($_service_id) {
            $_receipt = Mysql('mysql')->query("select level_title,discount from member_level,service_mediscount where member_level.id eq service_mediscount.member_level and service_id eq " . $_service_id);
            if ($_receipt) {
                foreach ($_receipt as $k => $v) {
                    $v['discount'] = (doubleval($v['discount']) * 10) . '  折';
                    if ($v['discount'] == 10) {
                        $v['discount'] = '无折扣';
                    }
                    $_return .= "<li style='display: flex;float: left;width: 30%'>
                                  <strong style=\"width: 100px\">" . $v['level_title'] . "<font color=\"#ff0000\">*</font></strong>
                                  <div class=\"fl\" style=\"width: auto\"><input type=\"text\" value=\"" . $v['discount'] . "\"style=\"width: 70px\" readonly></div>
                               </li>";
                }
                Session('serviceMediscountInfo' . $_service_id, $_return);
            }
        }
    }
    return $_return;
}

/**
 * @access public
 * @param int $_pro_id
 * @return  string
 * @context 服务列表中会员折扣查询
 */
function getProMediscount($_pro_id)
{
    $_return = null;
    if ($_pro_id) {
        $_receipt = Mysql("mysql")->query("select med.*,lev.level_title,pro.biz_pro_title
                                          from biz_pro_mediscount as med,member_level as lev,biz_pro as pro
                                          where med.member_level eq lev.id and pro.id eq med.biz_pro_id and biz_pro_id eq " . $_pro_id);
        if ($_receipt) {
            foreach ($_receipt as $k => $v) {
                $v['discount'] = (doubleval($v['discount']) * 10) . '  折';
                if ($v['discount'] == 10) {
                    $v['discount'] = '无折扣';
                }
                $_return .= "<li>
                                  <strong style=\"width: 100px\">" . $v['level_title'] . "<font color=\"#ff0000\">*</font></strong>
                                  <div class=\"fl\" style=\"width: 80px\"><input type=\"text\" value=\"" . $v['discount'] . "\"style=\"width: 70px\" readonly></div>
                               </li>";
            }
        }
    }
    return $_return;
}

/**
 * @access public
 * @param string $_context
 * @return  string
 * @context 文章内容长度判断
 */
function getLength($_context)
{
    $_receipt = 0;
    if (!empty($_context)) {
        $_receipt = mb_strlen(trim($_context));
    }
    return $_receipt;
}

/**
 * @access public
 * @param string $_context
 * @return  string
 * @context 文章内容长度截取显示
 */
function getLengthContext($_context)
{
    return mb_substr($_context, 0, 6);
}

/**
 * @access public
 * @param string $_context
 * @return  string
 * @context 俱乐部文章内容长度截取显示
 */
function getClubContent($_context)
{
    return mb_substr($_context, 0, 40);
}

/**
 * @access public
 * @param string $_context
 * @return  string
 * @context 积分兑换商品标题长度截取显示
 */
function getProTitleContent($_context)
{
    return mb_substr($_context, 0, 4);
}

/**
 * @access public
 * @param int $_active_id
 * @return  string
 * @context 活动列表中会员折扣查询
 */
function getActiveMediscount($_active_id)
{
    $_return = null;
    if ($_active_id) {
        $_car_res = Mysql('mysql')->query("select level_title,discount from car_level,active_car_mediscount where car_level.id eq active_car_mediscount.car_level_id and active_id eq " . $_active_id);
        if ($_car_res) {
            foreach ($_car_res as $kk => $vv) {
                $_return .= "<li>
                                  <strong style=\"width: 100px\">" . $vv['level_title'] . "<font color=\"#ff0000\">*</font></strong>
                                  <div class=\"fl\" style=\"width: 80px\"><input type=\"text\" value=\"" . $vv['discount'] . "元" . "\"style=\"width: 70px\" readonly></div>
                               </li>";
            }
        }
        $_receipt = Mysql('mysql')->query("select level_title,discount from member_level,active_mediscount where member_level.id eq active_mediscount.member_level and active_id eq " . $_active_id);
        if ($_receipt) {
            foreach ($_receipt as $k => $v) {
                $_return .= "<li>
                                  <strong style=\"width: 100px\">" . $v['level_title'] . "<font color=\"#ff0000\">*</font></strong>
                                  <div class=\"fl\" style=\"width: 80px\"><input type=\"text\" value=\"" . $v['discount'] . "\"style=\"width: 70px\" readonly></div>
                               </li>";
            }
        }
    }
    return $_return;
}

/**
 * @access public
 * @param int $_service_id
 * @return  string
 * @context 服务列表门店价格查询
 */
function getBizPrice($_service_id)
{
//    $_return = null;
    $bizId = Session('biz_id');
    $_return = Session($bizId . 'BizPriceInfo' . $_service_id);
    if (empty($_return)) {
        if ($_service_id) {
            $_where = null;
            if (!empty($bizId))
                $_where .= " and biz_id = " . $bizId;
            $_biz_price = Mysql('mysql')->query("select level_title,discount from car_level,service_car_mediscount where car_level.id eq service_car_mediscount.car_level_id and service_type eq 2 and service_id eq " . $_service_id . $_where);
            if ($_biz_price) {
                foreach ($_biz_price as $k => $v) {
                    $_return .= "<li style='display: flex;float: left;width: 30%'>
                                  <strong style=\"width: 100px\">" . $v['level_title'] . "<font color=\"#ff0000\">*</font></strong>
                                  <div class=\"fl\" style=\"width: auto\"><input type=\"text\" value=\"" . $v['discount'] . "元" . "\"style=\"width: 70px\" readonly></div>
                               </li>";
                }
            }
            Session($bizId . 'BizPriceInfo' . $_service_id, $_return);
        }
    }
    return $_return;
}

/**
 * @access public
 * @param int $_service_id
 * @return  string
 * @context 服务列表线上价格查询
 */
function getOnlinePrice($_service_id)
{
    $bizId = Session('biz_id');
    $_return = Session($bizId . 'onlinePriceInfo' . $_service_id);
//    $_return = null;
    if (empty($_return)) {
        if ($_service_id) {
            $_where = null;
            if (!empty($bizId))
                $_where .= " and biz_id = " . $bizId;
            $_online_price = Mysql('mysql')->query("select level_title,discount from car_level,service_car_mediscount where car_level.id eq service_car_mediscount.car_level_id and service_type eq 1 and service_id eq " . $_service_id . $_where);
            if ($_online_price) {
                foreach ($_online_price as $k => $v) {
                    $_return .= "<li style='display: flex;float: left;width: 30%'>
                                  <strong style=\"width: 100px\">" . $v['level_title'] . "<font color=\"#ff0000\">*</font></strong>
                                  <div class=\"fl\" style=\"width: auto\"><input type=\"text\" value=\"" . $v['discount'] . "元" . "\"style=\"width: 70px\" readonly></div>
                               </li>";
                }
                Session($bizId . 'onlinePriceInfo' . $_service_id, $_return);
            }
        }
    }
    return $_return;
}

/**
 * @access public
 * @param int $_type
 * @return  string
 * @context 配送方式
 */
function getDelivery($_type)
{
    switch (intval($_type)) {
        case 1:
        default:
            return "到店自提";
            break;
        case 2:
            return "包邮";
            break;
    }
}

/**
 * @access public
 * @param $_type
 * @return string
 * @context 积分来源
 */
function getIntegralType($_type)
{
    switch (intval($_type)) {
        case -12:
            return "线上购买商品额外赠送";
            break;
        case -11:
            return "线下充值";
            break;
        case -10:
            return "线下升级";
            break;
        case -6:
            return "线下储值";
            break;
        case -3:
            return "门店购买服务";
            break;
        case -2:
            return "评论分享";
            break;
        case -1:
            return "实名认证";
            break;
        case 0:
        default:
            return "额外赠送";
            break;
        case 1:
            return "首次登陆";
            break;
        case 2:
            return "分享注册";
            break;
        case 3:
            return "线上购买服务";
            break;
        case 4:
            return "评论订单";
            break;
        case 5:
            return "积分兑换";
            break;
        case 6:
            return "办理会员";
            break;
        case 7:
            return "关注公众号";
            break;
        case 8:
            return "分享文章";
            break;
        case 9:
            return "注册赠送";
            break;
        case 10:
            return "线上升级";
            break;
        case 11:
            return "线上充值";
            break;
        case 12:
            return "门店购买商品额外赠送";
            break;
        case 13:
            return "活动赠送";
            break;
        case 14:
            return "查看文章";
            break;
        case 15:
            return "分享服务";
            break;
        case 16:
            return "分享商家";
            break;
        case 17:
            return "分享二手车";
            break;
        case 18:
            return "分享用户";
            break;
        case 19:
            return "推荐储值用户";
            break;
        case 20:
            return "推荐用户充值";
            break;
        case 21:
            return "推荐升级";
            break;
        case 22:
            return "下载APP";
            break;
        case 23:
            return "成为推广员";
            break;
        case 24:
            return "签到奖励";
            break;
        case 25:
            return "商家推广";
            break;
        case 26:
            return "分享联盟商家";
            break;
        case 27:
            return "商家支付";
            break;
        case 28:
            return "服务消费";
            break;
    }
}

/**
 * @access public
 * @param $_type
 * @return string
 * @context 卡券类型
 */
function getCardType($_type)
{
    switch (intval($_type)) {
        case 1:
        default:
            return "服务卡券";
            break;
        case 2:
            return "现金抵值券";
            break;
        case 3:
            return "商品卡券";
            break;
    }
}

/**
 * @access public
 * @param $_type
 * @return string
 * @context 卡券来源
 */
function getVoucherSource($_type)
{
    switch (intval($_type)) {
        case 1:
        default:
            return "购买服务";
            break;
        case -1:
            return "服务赠送";
            break;
        case 2:
            return "活动获得";
            break;
        case -2:
            return "活动赠送";
            break;
        case 3:
            return "商家门店赠送";
            break;
        case 4:
            return "现金红包";
            break;
        case 5:
            return "办理会员";//线上
            break;
        case 6:
            return "办理会员";//门店
            break;
        case 7:
            return "线上升级";
            break;
        case 8:
            return "门店升级";
            break;
        case 9:
            return "线上充值";
            break;
        case 10:
            return "门店充值";
            break;
        case 11:
            return "商家线上赠送";
            break;
    }
}

/**
 * @access public
 * @param $_type
 * @return string
 * @context 卡券来源
 */
function getVoucherPayType($_type)
{
    switch (intval($_type)) {
        case 0:
        default:
            return "活动获得";
            break;
        case 1:
            return "微信";
            break;
        case 2:
            return "余额";
            break;
    }
}

/**
 * @param bool $mark
 * @return mixed
 * @content 获取门店数组信息
 */
function getBizArrInfo($mark = false)
{
    if ($mark) {
        $bizInfo = Mysql("mysql")->table("biz")->field(array('id', 'biz_title'))->where(array('biz_status' => 1))->fetchType(2)->select();
        Session('bizInfo', $bizInfo);
    } else {
        $bizInfo = Session('bizInfo');
        if (empty($bizInfo)) {
            $bizInfo = Mysql("mysql")->table("biz")->field(array('id', 'biz_title'))->where(array('biz_status' => 1))->fetchType(2)->select();
            Session('bizInfo', $bizInfo);
        }
        return $bizInfo;
    }
}
